<template>
  <div class="academy-container">
    <div class="main-info-title fs18 flex flex-row-center">
      <span>院校</span>
      <el-button type="primary" style="margin-left: auto" @click="addAcademy">
        新建院校
      </el-button>
    </div>
    <HHsearch
      ref="search"
      :search-options="searchOptions"
      :btn-option="1"
      @search="search"
      @reset="reset"
    ></HHsearch>
    <HHtable
      ref="table"
      :border="true"
      :total="total"
      :table-column="tableColumn"
      :btn-option="btnOption"
      :table-data="tableData"
      @page-click="pageClick"
    >
      <!-- 院校logo -->
      <template #academyLogo="{ data }">
        <el-image
          style="width: 50px; height: 50px"
          :src="data.schoolIcon"
          fit="cover"
        ></el-image>
      </template>

      <!-- 院校简介 -->
      <template #introduction="{ data }">
        <el-tooltip
          v-if="data.introductionColleges.length > 20"
          class="item"
          effect="dark"
          placement="right-start"
        >
          <div slot="content" style="width: 500px">
            {{ data.introductionColleges }}
          </div>
          <div class="clamp">{{ data.introductionColleges }}</div>
        </el-tooltip>
        <div v-else class="clamp">{{ data.introductionColleges }}</div>
      </template>

      <!-- 院校风管 -->
      <template #academyImg="{ data }">
        <el-image
          v-for="(item, index) in data.schoolImgList"
          :key="index"
          style="width: 50px; height: 50px; margin-right: 5px"
          :src="item"
          fit="cover"
          :preview-src-list="data.schoolImgList"
        ></el-image>
      </template>

      <!-- 开设专业 -->
      <template #majorNames="{ data }">
        <el-tooltip
          v-if="data.majorNames.length > 20"
          class="item"
          effect="dark"
          placement="right-start"
        >
          <div slot="content" style="width: 500px">
            {{ data.majorNames }}
          </div>
          <div class="clamp">{{ data.majorNames }}</div>
        </el-tooltip>
        <div v-else class="clamp">{{ data.majorNames }}</div>
      </template>
    </HHtable>
    <el-dialog
      :title="dialogTitle"
      :visible.sync="dialogTableVisible"
      width="50%"
    >
      <el-steps
        :active="stepActive"
        finish-status="success"
        simple
        style="margin-bottom: 20px"
      >
        <el-step title="院校概况"></el-step>
        <el-step title="招录数据"></el-step>
        <!-- <el-step title="开设专业"></el-step> -->
      </el-steps>
      <!-- 院校概况 -->
      <div v-show="stepActive === 1" class="step1 flex flex-center">
        <el-form
          ref="form"
          :model="form"
          label-width="80px"
          :rules="rules"
          label-position="right"
        >
          <el-form-item label="院校名称" prop="schoolName">
            <el-input
              v-model="form.schoolName"
              placeholder="请输入群名"
            ></el-input>
          </el-form-item>
          <el-form-item label="院校logo" prop="cover">
            <el-upload
              class="avatar-uploader"
              :action="`${baseURL}/hce/common/upload.do`"
              list-type="picture-card"
              :file-list="form.cover"
              :limit="1"
              :on-exceed="handleExceed"
              :on-remove="handleRemove"
              :on-success="handleSuccess"
              accept="image/jpg, image/jpeg,image/png"
            >
              <i class="el-icon-plus"></i>
              <div slot="tip" class="el-upload__tip">
                建议上传1:1尺寸图片，避免显示不全
                <strong style="color: red">(只能上传一张图片)</strong>
              </div>
            </el-upload>
          </el-form-item>
          <el-form-item label="标签" prop="">
            <el-select
              v-model="form.schoolNature"
              placeholder="请选择办学性质"
              clearable
            >
              <el-option
                v-for="item in academyNature"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
            <span style="margin: 0 5px"></span>
            <el-select
              v-model="form.schoolAddress"
              placeholder="请选择所在地区"
              clearable
            >
              <el-option
                v-for="item in areaList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
            <span style="margin: 0 5px"></span>
            <el-select
              v-model="form.schoolType"
              placeholder="请选择院校类型"
              clearable
            >
              <el-option
                v-for="item in academyTypeList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="院校代码" prop="schoolCode">
            <el-input
              v-model="form.schoolCode"
              placeholder="请输入院校代码"
            ></el-input>
          </el-form-item>
          <el-form-item label="院校官网" prop="schoolWebsite">
            <el-input
              v-model="form.schoolWebsite"
              placeholder="请输入院校官网"
              maxlength="200"
            ></el-input>
          </el-form-item>
          <el-form-item label="招生热线" prop="recruitmentHotline">
            <el-input
              v-model="form.recruitmentHotline"
              placeholder="请输入招生热线"
            ></el-input>
          </el-form-item>
          <el-form-item label="院校简介" prop="introductionColleges">
            <el-input
              v-model="form.introductionColleges"
              placeholder="请输入院校简介"
              type="textarea"
            ></el-input>
          </el-form-item>
          <el-form-item label="校园风光" prop="cover2">
            <el-upload
              class="avatar-uploader"
              :action="`${baseURL}/hce/common/upload.do`"
              list-type="picture-card"
              :file-list="form.cover2"
              :on-exceed="handleExceed"
              :on-remove="handleRemove1"
              :on-success="handleSuccess1"
              :limit="10"
              accept="image/jpg, image/jpeg,image/png"
            >
              <i class="el-icon-plus"></i>
              <div slot="tip" class="el-upload__tip">
                建议上传1:1尺寸图片，避免显示不全
                <strong style="color: red">(只能上传十张图片)</strong>
              </div>
            </el-upload>
          </el-form-item>
        </el-form>
      </div>
      <!-- 招录数据 -->
      <div v-show="stepActive === 2" class="step2">
        <div class="step2-top">
          <el-button type="primary" @click="showRankDialog">
            添加招录数据
          </el-button>
        </div>
        <HHtable
          :total="0"
          :height="300"
          :table-column="tableColumn2"
          :btn-option="btnOption2"
          :table-data="tableData2"
        ></HHtable>
        <!-- 添加招录数据 -->
        <el-dialog
          :title="dialogTitle2"
          :visible.sync="dialogTableVisible2"
          width="500px"
          append-to-body
          :close-on-click-modal="false"
        >
          <el-form :model="form2" label-width="120px" label-position="left">
            <el-form-item label="年份" prop="year">
              <!-- <el-date-picker v-model="form2.year" type="year" placeholder="选择年">
              </el-date-picker> -->
              <el-input
                v-model="form2.year"
                onkeyup="value=value.replace(/[^\d]/g,'')"
                placeholder="请输入年份"
              ></el-input>
            </el-form-item>
            <el-form-item label="计划招生人数" prop="planNumber">
              <el-input
                v-model="form2.planNumber"
                placeholder="请输入计划招生人数"
              ></el-input>
            </el-form-item>
            <el-form-item label="市内最低分" prop="cityLine">
              <el-input
                v-model="form2.cityLine"
                placeholder="请输入市内最低分"
              ></el-input>
            </el-form-item>
            <el-form-item label="市外最低分" prop="outsideCityLine">
              <el-input
                v-model="form2.outsideCityLine"
                placeholder="请输入市外最低分"
              ></el-input>
            </el-form-item>
            <el-form-item label="市内最低排名" prop="cityRanked">
              <el-input
                v-model="form2.cityRanked"
                placeholder="请输入市内最低排名"
              ></el-input>
            </el-form-item>
            <el-form-item label="市外最低排名" prop="outsideCityRanked">
              <el-input
                v-model="form2.outsideCityRanked"
                placeholder="请输入市外最低排名"
              ></el-input>
            </el-form-item>
            <el-form-item label="市内投档人数" prop="cityPeople">
              <el-input
                v-model="form2.cityPeople"
                placeholder="请输入市内投档人数"
              ></el-input>
            </el-form-item>
            <el-form-item label="市外投档人数" prop="outsideCityPeople">
              <el-input
                v-model="form2.outsideCityPeople"
                placeholder="请输入市外投档人数"
              ></el-input>
            </el-form-item>
            <el-form-item label="补录分数" prop="collectionPoints">
              <el-input
                v-model="form2.collectionPoints"
                placeholder="请输入补录分数"
              ></el-input>
            </el-form-item>
          </el-form>
          <div class="flex flex-center" style="margin-top: 50px">
            <el-button type="primary" @click="addRankData">确定</el-button>
          </div>
        </el-dialog>
      </div>
      <!-- 开设专业 -->
      <div v-show="stepActive === 3" class="step3">
        <div class="step3-top">
          <el-button type="primary" @click="showSpecialtyDialog">
            选择专业
          </el-button>
        </div>
        <HHtable
          ref="table3"
          :total="0"
          :height="300"
          :table-column="tableColumn3"
          :btn-width="150"
          :btn-option="btnOption3"
          :table-data="tableData3"
        >
          <!-- 相关证书 -->
          <template #certificateIds="{ data }">
            <div class="clamp">{{ data.certificateIds }}</div>
          </template>

          <!-- 简介说明 -->
          <template #introduction="{ data }">
            <div class="clamp">{{ data.introduction }}</div>
          </template>
        </HHtable>
        <!-- 添加招录数据 -->
        <el-dialog
          :title="dialogTitle3"
          :visible.sync="dialogTableVisible3"
          width="450px"
          append-to-body
          :close-on-click-modal="false"
        >
          <el-form :model="form3" label-width="120px" label-position="left">
            <el-form-item label="专业名称" prop="majorId">
              <el-select
                v-model="form3.majorId"
                filterable
                placeholder="请输入专业名称"
              >
                <el-option
                  v-for="item in specialtyList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="专业代码">
              <el-input
                v-model="form3.majorCode"
                placeholder="请输入专业代码"
                style="width: 215px"
              ></el-input>
            </el-form-item>
            <el-form-item label="计划招录人数">
              <el-input
                v-model="form3.plannedRecruitsNum"
                placeholder="请输入计划招录人数"
                style="width: 215px"
              ></el-input>
            </el-form-item>
            <el-form-item label="相关证书">
              <el-select
                v-model="form3.certificateIds"
                placeholder="请选择相关证书"
                multiple
                filterable
              >
                <el-option
                  v-for="item in typeNameList"
                  :key="item.id"
                  :label="item.certificateName"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="地区限制">
              <el-select
                v-model="form3.regionalRestrictions"
                placeholder="请选择地区限制"
              >
                <el-option
                  v-for="item in areaList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="最低分">
              <el-input
                v-model="form3.lowestScore"
                placeholder="请输入最低分"
                style="width: 215px"
              ></el-input>
            </el-form-item>
            <el-form-item label="最高分">
              <el-input
                v-model="form3.highestScore"
                placeholder="请输入最高分"
                style="width: 215px"
              ></el-input>
            </el-form-item>
            <el-form-item label="排位">
              <el-input
                v-model="form3.qualifying"
                placeholder="请输入排位"
                style="width: 215px"
              ></el-input>
            </el-form-item>
            <el-form-item label="平均分">
              <el-input
                v-model="form3.evaluationPoints"
                placeholder="请输入平均分"
                style="width: 215px"
              ></el-input>
            </el-form-item>
            <el-form-item label="简介说明">
              <el-input
                v-model="form3.introduction"
                type="textarea"
                :rows="3"
                placeholder="请输入简介说明"
                style="width: 215px"
              ></el-input>
            </el-form-item>
          </el-form>
          <div class="flex flex-center" style="margin-top: 50px">
            <el-button type="primary" @click="addSpecialty">确定</el-button>
          </div>
        </el-dialog>
      </div>
      <div class="btn-container flex flex-center">
        <el-button v-if="stepActive !== 1" @click="prev">上一步</el-button>
        <el-button
          v-if="stepActive != 3"
          type="primary"
          @click="saveAcademyInfo"
        >
          保存
        </el-button>
        <el-button v-if="stepActive === 1" @click="next">下一步</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import HHsearch from '@/components/HH-search'
  import HHtable from '@/components/HH-table'
  import {
    getAcademyList,
    addAcademyInfo,
    updateAcademyInfo,
    deleteAcademyInfo,
    getAreaList,
    academyTypeList,
    getTypeNameList,
  } from '@/api/academy'
  import { specialtyList } from '@/api/specialty'
  import _ from 'loadsh'
  export default {
    components: {
      HHsearch,
      HHtable,
    },
    data() {
      return {
        total: 0,
        dialogTableVisible: false,
        dialogTableVisible2: false,
        dialogTableVisible3: false,
        dialogTitle: '新建院校信息',
        dialogTitle2: '新建招录数据',
        dialogTitle3: '选择专业',
        stepActive: 1,
        form2Index: '',
        form3Index: '',
        specialtyObj: {},
        form: {
          schoolName: '',
          schoolIcon: '',
          schoolNature: '',
          schoolAddress: '',
          schoolType: '',
          schoolCode: '',
          schoolWebsite: '',
          recruitmentHotline: '',
          introductionColleges: '',
          cover: [],
          cover2: [],
          schoolImgList: [],
          schoolDataList: [], //招录数据
          schoolRecruitmentDTOList: [], //选择专业
        },
        form2: {
          year: '',
          planNumber: 0,
          cityLine: 0,
          outsideCityLine: 0,
          cityRanked: 0,
          outsideCityRanked: 0,
          cityPeople: 0,
          outsideCityPeople: 0,
          collectionPoints: 0,
        },
        form3: {
          majorId: '',
          majorCode: '',
          certificateIds: [],
          regionalRestrictions: '',
          lowestScore: 0,
          highestScore: 0,
          qualifying: 0,
          evaluationPoints: 0,
          introduction: '',
        },
        rules: {
          schoolName: [
            { required: true, message: '请输入院校名称', trigger: 'blur' },
          ],
          schoolCode: [
            { required: true, message: '请输入院校代码', trigger: 'blur' },
          ],
          cover: [{ required: true, message: '请上传院校logo' }],
        },
        model: '',
        params: {
          pageNum: 1,
          pageSize: 10,
          certificateId: '',
          majorId: '',
          schoolAddress: '',
          schoolName: '',
          schoolNature: '',
          schoolType: '',
        },
        academyNature: [
          {
            label: '公办',
            value: '公办',
          },
          {
            label: '民办',
            value: '民办',
          },
        ],
        areaList: [],
        academyTypeList: [],
        typeNameList: [],
        specialtyList: [],
        tableColumn: [
          {
            prop: 'schoolName',
            label: '院校名称',
          },
          {
            label: '院校logo',
            slotContent: 'academyLogo',
          },
          {
            prop: 'schoolNature',
            label: '办学性质',
          },
          {
            prop: 'schoolAddress',
            label: '所在地区',
          },
          {
            prop: 'schoolType',
            label: '院校类型',
          },
          {
            prop: 'schoolCode',
            label: '院校代码',
          },
          {
            prop: 'schoolWebsite',
            label: '院校官网',
          },
          {
            prop: 'recruitmentHotline',
            label: '招生热线',
          },
          {
            // prop: "introductionColleges",
            label: '院校简介',
            slotContent: 'introduction',
          },
          {
            label: '院校风光',
            width: '200',
            slotContent: 'academyImg',
          },
          {
            prop: 'majorNames',
            label: '开设专业',
            slotContent: 'majorNames',
          },
        ],
        tableData: [],
        tableColumn2: [
          {
            prop: 'year',
            label: '年份',
          },
          {
            prop: 'planNumber',
            label: '计划招生人数',
          },
          {
            prop: 'cityLine',
            label: '市内最低分',
          },
          {
            prop: 'outsideCityLine',
            label: '市外最低分',
          },
          {
            prop: 'cityRanked',
            label: '市内最低排名',
          },
          {
            prop: 'outsideCityRanked',
            label: '市外最低排名',
          },
          {
            prop: 'cityPeople',
            label: '市内投档人数',
          },
          {
            prop: 'outsideCityPeople',
            label: '市外投档人数',
          },
          {
            prop: 'collectionPoints',
            label: '补录分数',
          },
        ],
        tableData2: [],
        tableColumn3: [
          {
            prop: 'majorName',
            label: '专业名称',
            width: '120px',
          },
          {
            prop: 'majorCode',
            label: '专业代码',
          },
          {
            prop: 'plannedRecruitsNum',
            label: '计划招录人数',
          },
          {
            // prop: "certificateIds",
            label: '相关证书',
            slotContent: 'certificateIds',
            width: '120px',
          },
          {
            prop: 'regionalRestrictions',
            label: '地区限制',
          },
          {
            prop: 'highestScore',
            label: '最高分',
          },
          {
            prop: 'lowestScore',
            label: '最低分',
          },
          {
            prop: 'qualifying',
            label: '排位',
          },
          {
            prop: 'evaluationPoints',
            label: '平均分',
          },
          {
            prop: 'introduction',
            label: '简介说明',
            slotContent: 'introduction',
          },
        ],
        tableData3: [],
        searchOptions: [
          {
            type: 'text',
            prop: 'schoolName',
            span: 6,
            label: '院校名称：',
            placeholder: '请输入搜索',
          },
          {
            type: 'select',
            prop: 'schoolNature',
            label: '办学性质：',
            span: 5,
            placeholder: '请选择办学性质',
            arr: [
              {
                label: '公办',
                value: '公办',
              },
              {
                label: '民办',
                value: '民办',
              },
            ],
          },
          {
            type: 'select',
            prop: 'schoolAddress',
            label: '所在地区：',
            span: 5,
            placeholder: '请选择地区',
            arr: [],
          },
          {
            type: 'select',
            prop: 'schoolType',
            label: '院校类型：',
            span: 5,
            placeholder: '请选择类型',
            arr: [],
          },
          {
            type: 'text',
            prop: 'schoolCode',
            label: '院校代码：',
            span: 6,
            placeholder: '请输入搜索',
          },
        ],
        btnOption: [
          {
            type: 'primary',
            size: 'mini',
            text: '修改',
            show: true,
            func: this.edit,
          },
          {
            type: 'danger',
            size: 'mini',
            text: '删除',
            show: true,
            func: this.delete,
          },
        ],
        btnOption2: [
          {
            type: 'primary',
            size: 'mini',
            text: '修改',
            show: true,
            func: this.editRank,
          },
          {
            type: 'danger',
            size: 'mini',
            text: '删除',
            show: true,
            func: this.deleteRank,
          },
          {
            type: 'success',
            size: 'mini',
            text: '选择专业',
            show: true,
            func: this.selectSpecialty,
          },
        ],
        btnOption3: [
          {
            type: 'primary',
            size: 'mini',
            text: '修改',
            show: true,
            func: this.editSpecialty,
          },
          {
            type: 'danger',
            size: 'mini',
            text: '删除',
            show: true,
            func: this.deleteSpecialty,
          },
        ],
      }
    },
    mounted() {
      this.initData()
      this.getAcademyList()
      // 获取专业分类证书
      getTypeNameList().then((res) => {
        if (res.code === 200) {
          this.typeNameList = res.data
          // 获取专业id下拉
          specialtyList().then((res) => {
            if (res.code === 200) {
              this.specialtyList = res.data
            }
          })
        }
      })
    },
    methods: {
      async initData() {
        const res = await getAreaList()
        const res1 = await academyTypeList()
        this.areaList = res.data
        this.searchOptions[2].arr = res.data
        this.academyTypeList = res1.data
        this.searchOptions[3].arr = res1.data
      },
      // 获取列数据
      getAcademyList() {
        this.$refs.table.loading = true
        getAcademyList(this.params).then((res) => {
          if (res.code === 200) {
            this.total = res.data.total
            this.tableData = res.data.result
            setTimeout(() => {
              this.$refs.table.loading = false
            }, 1000)
          } else {
            this.$refs.table.loading = false
          }
        })
      },
      addAcademy() {
        this.dialogTitle = '新建院校信息'
        this.dialogTableVisible = true
        this.stepActive = 1
        this.form = {
          schoolName: '',
          schoolCode: '',
          schoolNature: '',
          schoolAddress: '',
          schoolType: '',
          schoolWebsite: '',
          recruitmentHotline: '',
          introductionColleges: '',
          cover: [],
          cover2: [],
          schoolImgList: [],
          schoolDataList: [], //招录数据
          schoolRecruitmentDTOList: [], //选择专业
        }
        this.tableData2 = []
        this.tableData3 = []
      },
      // 修改列数据
      edit(data) {
        const allData = data
        const arr = Object.keys(this.form)
        arr.forEach((item) => {
          if (item === 'cover') {
            const cover = []
            cover.push({ url: allData.schoolIcon })
            this.form.cover = cover
          } else if (item === 'cover2') {
            const cover2 = []
            for (let i = 0; i < allData.schoolImgList.length; i++) {
              cover2.push({ url: allData.schoolImgList[i] })
            }
            this.form.cover2 = cover2
          } else {
            this.form[item] = allData[item]
          }
        })
        if (allData.schoolDataList.length > 0) {
          this.tableData2 = _.cloneDeep(allData.schoolDataList).sort(
            (a, b) => a.year - b.year
          )
        } else {
          // 重置数据，避免无数据时，复用上一次的数据
          this.tableData2 = []
        }
        this.stepActive = 1
        this.form.id = data.id
        this.dialogTableVisible = true
        this.dialogTitle = '修改院校信息'
      },
      //  删除列数据
      delete(data) {
        const params = {
          ids: data.id,
        }
        deleteAcademyInfo(params).then((res) => {
          if (res.code === 200) {
            this.$baseMessage('删除成功', 'success')
            this.getAcademyList()
          }
        })
      },
      // 添加或修改招录数据
      addRankData() {
        //  必须填写年份
        if (!this.form2.year) {
          this.$baseMessage('请填写年份', 'error')
          return
        }
        // 年份不能重复
        const yearKeys = this.form.schoolDataList.map((item) => item.year)
        if (
          yearKeys.includes(this.form2.year) &&
          this.dialogTitle2 != '修改招录数据'
        ) {
          this.$baseMessage('请误填写重复年份', 'error')
          return
        }
        const form = _.cloneDeep(this.form2)
        const index = this.form2Index
        if (index === '') {
          //  新增
          this.form.schoolDataList.push(form)
          this.tableData2.push(form)
          this.tableData2.sort((a, b) => a.year - b.year)
          this.$baseMessage('添加成功', 'success')
        } else {
          //  修改
          this.form.schoolDataList[index] = form
          this.tableData2.splice(index, 1, form)
          this.tableData2.sort((a, b) => a.year - b.year)
          this.form2Index = ''
          this.$baseMessage('修改成功', 'success')
        }
        this.dialogTableVisible2 = false
      },
      // 修改招录数据行
      editRank(data, index) {
        const arr = Object.keys(data)
        arr.forEach((item) => {
          this.form2[item] = data[item]
        })
        this.form2Index = index
        this.dialogTitle2 = '修改招录数据'
        this.dialogTableVisible2 = true
      },
      // 删除招录数据行
      deleteRank(data, index) {
        const { year } = data
        const arr = this.tableData2
        const form = _.cloneDeep(this.form.schoolRecruitmentDTOList)
        const filterArray = form.filter((item) => item.year != year)
        this.form.schoolRecruitmentDTOList = filterArray
        arr.splice(index, 1)
        this.form.schoolDataList = this.tableData2 = arr
        this.$baseMessage('删除成功', 'success')
      },
      // 选择专业添加数据到表格
      selectSpecialty(data) {
        this.specialtyObj = data
        this.stepActive = 3
        const arr = _.cloneDeep(this.form.schoolRecruitmentDTOList)
        const length = arr.length
        const arr2 = arr.filter((item) => item.year === data.year)
        if (this.dialogTitle === '新建院校信息') {
          arr2.map((item1) => {
            // 相关证书数据整合
            const ids = Object.values(item1.certificateIds)
            const keys = Object.keys(this.typeNameList)
            const arr = []
            ids.map((item) => {
              keys.map((el) => {
                if (item == this.typeNameList[el].id) {
                  arr.push(this.typeNameList[el].certificateName)
                }
              })
            })
            item1.certificateIds = arr.join(',')
            // 专业名称数据整合
            const id = item1.majorId
            let specialtyName = ''
            const specialtyList = this.specialtyList
            for (let i = 0; i < specialtyList.length; i++) {
              if (specialtyList[i].id == id) {
                specialtyName = specialtyList[i].name
              }
            }
            item1.majorName = specialtyName
            item1.id = length + 1000
          })
        }
        arr2.map((item1) => {
          // 相关证书数据整合
          const ids = Object.values(item1.certificateIds)
          const keys = Object.keys(this.typeNameList)
          const arr = []
          ids.map((item) => {
            keys.map((el) => {
              if (item == this.typeNameList[el].id) {
                arr.push(this.typeNameList[el].certificateName)
              }
            })
          })
          item1.certificateIds = arr.join(',')
          console.log('item1', item1)
        })
        this.tableData3 = arr2
        setTimeout(() => {
          this.$refs.table3.doLayout()
        }, 200)
      },
      // 编辑专业
      editSpecialty(data, index) {
        const { year, id } = data
        const arr = this.form.schoolRecruitmentDTOList
        const arr2 = arr.filter((item) => {
          if (item.year == year && item.id == id) {
            return item
          }
        })
        const obj = arr2[0]
        this.form3 = obj
        this.form3Index = index
        this.dialogTableVisible3 = true
      },
      deleteSpecialty(data, index) {
        const { year, majorCode } = data
        const arr = this.tableData3
        arr.splice(index, 1)
        this.tableData3 = arr
        this.form.schoolRecruitmentDTOList.map((item, index) => {
          if (item.year === year && item.majorCode == majorCode) {
            this.form.schoolRecruitmentDTOList.splice(index, 1)
          }
        })
        // this.$baseMessage("删除成功", "success");
      },
      // 添加专业
      addSpecialty() {
        this.form3.year = this.specialtyObj.year
        const form = _.cloneDeep(this.form3)
        // 相关证书数据整合
        const ids = Object.values(form.certificateIds)
        const keys = Object.keys(this.typeNameList)
        const arr = []
        ids.map((item) => {
          keys.map((el) => {
            if (item == this.typeNameList[el].id) {
              arr.push(this.typeNameList[el].certificateTypeName)
            }
          })
        })
        form.certificateIds = arr.join(',')
        // 专业名称数据整合
        const id = form.majorId
        let specialtyName = ''
        const specialtyList = this.specialtyList
        for (let i = 0; i < specialtyList.length; i++) {
          if (specialtyList[i].id == id) {
            specialtyName = specialtyList[i].name
          }
        }
        form.majorName = specialtyName
        const index = this.form3Index
        if (index === '') {
          // 新增专业
          this.form.schoolRecruitmentDTOList.push(this.form3)
          this.tableData3.push(form)
        } else {
          // 修改专业
          this.form.schoolRecruitmentDTOList[index] = this.form3
          this.tableData3.splice(index, 1, form)
          this.form3Index = ''
        }
        this.dialogTableVisible3 = false
        // 表格重新计算
        this.$refs.table3.doLayout()
        this.$baseMessage('添加成功', 'success')
      },
      //  展示专业添加窗口
      showSpecialtyDialog() {
        this.dialogTitle3 = '选择专业'
        this.dialogTableVisible3 = true
        this.form3 = {
          majorCode: '',
          certificateIds: [],
          regionalRestrictions: '',
          lowestScore: 0,
          highestScore: 0,
          qualifying: 0,
          evaluationPoints: 0,
          introduction: '',
        }
      },
      // 上一步
      prev() {
        let stepActive = this.stepActive
        this.stepActive = stepActive - 1
      },
      // 下一步
      next() {
        if (this.stepActive === 1) {
          this.$refs.form.validate((valid) => {
            if (valid) {
              let stepActive = this.stepActive
              this.stepActive = stepActive + 1
            } else {
              this.$baseMessage('请输入必填字段', 'warning')
            }
          })
        } else {
          let stepActive = this.stepActive
          this.stepActive = stepActive + 1
        }
      },
      // 展示招录数据窗口
      showRankDialog() {
        this.dialogTitle2 = '新建招录数据'
        this.dialogTableVisible2 = true
        this.form2 = {
          year: '',
          planNumber: 0,
          cityLine: 0,
          outsideCityLine: 0,
          cityRanked: 0,
          outsideCityRanked: 0,
          cityPeople: 0,
          outsideCityPeople: 0,
          collectionPoints: 0,
        }
      },
      search(res) {
        const arr = Object.keys(res)
        for (let i = 0; i < arr.length; i++) {
          this.params[arr[i]] = res[arr[i]]
        }
        this.getAcademyList()
      },
      reset() {
        this.params = {
          pageNum: 1,
          pageSize: 10,
          certificateId: '',
          majorId: '',
          schoolAddress: '',
          schoolName: '',
          schoolNature: '',
          schoolType: '',
        }
        this.$refs.search.removeFilterArray()
        this.getAcademyList()
      },
      pageClick(pager) {
        this.params.pageNum = pager
        this.getAcademyList()
      },
      handleExceed() {
        this.$baseMessage('已超出最大上传数量', 'warning')
      },
      handleRemove() {
        this.form.schoolIcon = ''
        this.form.cover.pop()
      },
      handleSuccess(response) {
        this.form.schoolIcon = response.data[0].url
        this.form.cover.push({ url: response.data[0].url })
      },
      handleRemove1(file, fileList) {
        const { uid, url } = file
        const arr = this.form.cover2
        const arr2 = this.form.schoolImgList
        this.form.cover2 = arr.filter((item) => item.uid !== uid)
        this.form.schoolImgList = arr2.filter((item) => item !== url)
      },
      handleSuccess1(response) {
        this.form.schoolImgList.push(response.data[0].url)
        this.form.cover2.push({ url: response.data[0].url })
      },
      saveAcademyInfo() {
        const form = _.cloneDeep(this.form)
        delete form.cover
        delete form.cover2
        if (this.stepActive == 1) {
          // 直接在院校概况提交
          this.$refs.form.validate((valid) => {
            if (valid) {
              if (this.dialogTitle === '新建院校信息') {
                this.addAcademyInfo(form)
              } else {
                this.updateAcademyInfo(form)
              }
            } else {
              this.$baseMessage(res.msg, 'warning')
            }
          })
        } else {
          if (this.dialogTitle === '新建院校信息') {
            this.addAcademyInfo(form)
          } else {
            this.updateAcademyInfo(form)
          }
        }
      },
      addAcademyInfo(form) {
        addAcademyInfo(form).then((res) => {
          if (res.code === 200) {
            this.dialogTableVisible = false
            this.$baseMessage('添加成功', 'success')
            this.getAcademyList()
          } else {
            this.$baseMessage(res.msg, 'error')
          }
        })
      },
      updateAcademyInfo(form) {
        if (!form.schoolIcon) {
          form.schoolIcon = form.cover[0].url
        }
        updateAcademyInfo(form).then((res) => {
          if (res.code === 200) {
            this.dialogTableVisible = false
            this.$baseMessage('修改成功', 'success')
            this.getAcademyList()
          } else {
            this.$baseMessage(res.msg, 'error')
          }
        })
      },
    },
  }
</script>

<style lang="scss" scoped>
  @import '../../../assets/styles/common.css';
  .academy-container {
    .main-info-title {
      position: relative;
      height: 60px;
      margin-bottom: 20px;
      border-bottom: 1px solid #eee;

      &:after {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 80px;
        height: 3px;
        content: '';
        background-color: #409eff;
        border-radius: 3px;
        transition: all 0.5s ease;
      }

      &:hover:after {
        width: 120px;
      }
    }

    .clamp {
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 4;
      overflow: hidden;
    }

    .el-input,
    .el-textarea {
      width: 300px;
    }
  }
  ::v-deep {
    .el-upload-list__item {
      transition: none !important;
    }
  }
</style>
